package com.pagepub.expo.manager;



import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.pagepub.core.utils.StringUtil;
import com.pagepub.expo.dao.CorpPublicationPageDao;
import com.pagepub.expo.entity.CorpCatalog;
import com.pagepub.expo.entity.CorpPublicationPage;

@Service
@Transactional
@RemotingDestination(channels = { "my-amf", "my-secure-amf" })
public class  CorpPublicationPageMng {
	@Autowired
	private CorpPublicationPageDao corpPubPageDao;


	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpPublicationPage> findAll() {
		return corpPubPageDao.findAll();
	}
	


	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public int getCount(Map<String, String> param){
		return corpPubPageDao.getCount(param);
	}
	
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpPublicationPage> findByPage(int currentPage,int pageSize,Map<String, String> param){
		return corpPubPageDao.findByPage(currentPage, pageSize, param);
	}


	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpPublicationPage> findByPubId(int pubId){
		return corpPubPageDao.findByPubId(pubId);
	}
	
	
	@RemotingInclude
	public CorpPublicationPage add(CorpPublicationPage corpPublicationPage) {
		corpPubPageDao.insert(corpPublicationPage);
		return corpPubPageDao.findById(new Long(corpPublicationPage.getId()));
	}
	
	public boolean addPubPage(CorpPublicationPage bean) {
		return  corpPubPageDao.add(bean);
	}

	@RemotingInclude
	public Long remove(Long id) {
		corpPubPageDao.delete(id);
		return id;
	}
	
	@RemotingInclude
	public CorpPublicationPage findById(Long id) {
		return corpPubPageDao.findById(id);
	}

	public boolean isDeletePublicationpage(List publicationPageIdList) {
		boolean isDelete = false;
		String publicationPageId="";
		if(publicationPageIdList!=null&&publicationPageIdList.size()>0){
				
			for(Iterator ir=publicationPageIdList.iterator();ir.hasNext();){
				publicationPageId=(String) ir.next();
				corpPubPageDao.isDeletePublicationpage(StringUtil.stringToInt(publicationPageId));
			}
		}
			isDelete = true;
		
		return isDelete;
	}
	
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public int getOrderbyMax(int pubId){
		return corpPubPageDao.getOrderbyMax(pubId);
	}

	@RemotingInclude
	public CorpPublicationPage update(CorpPublicationPage corpCatalog) {
		corpPubPageDao.update(corpCatalog);
		return corpPubPageDao.findById(new Long(corpCatalog.getId()));
	}
	
	public boolean updatePubOrder(List publicationPageList) {
		boolean flag=false;
		if(publicationPageList!=null&&publicationPageList.size()>0){
			for(Iterator ir=publicationPageList.iterator();ir.hasNext();){
				CorpPublicationPage publicationpage=(CorpPublicationPage) ir.next();
				if(publicationpage!=null)
					corpPubPageDao.update(publicationpage);
				
			}
			flag=true;	
		}
		return flag;
	}
}
